// Pagename

var PN_POP_DOC_EDIT = "pop_doc_edit.php";

var PN_POP_KEYWORD_EDIT = "pop_keyword_edit.php";



// Action

var ACT_SEARCH = 'search';
var NUM_SEARCH_CONTEXT = '5';
var ACT_CHANGE_PAGE                 = 'change_page';

//end

var ACT_CLEAR_SEARCH = 'clear_search';

var ACT_DELETE = 'delete';

var ACT_GET_DATA                    = 5;

var ACT_EDIT			            = 'edit';

var ACT_SHOW_HIDE				    = 7;

var ACT_APPROVE_ALL                 = 8;

var ACT_LIST                        = 8;

var ACT_GET_DESCRIPTION             = 'get_description';

var ACT_ADD_COMMENT                 = 'add_comment';

var ACT_REGISTER_SUBCRIBE           = 11;

var ACT_ADD                         = 'add';

var ACT_UPDATE                      = 'update';

var ACT_GET_CONTENT                 = 'get_content';

var ACT_REFRESH_SEARCH_RESULT       = 16;

var ACT_REFRESH_KEYWORD             = 17;

var ACT_REBUILT			            = 18;

var ACT_UPDATERESULT                = 19;

var ACT_EXPORT                      = 20;

var ACT_GET_YLIST                   = 21;

var ACT_GET_BLIST                   = 22;

var ACT_LOGOUT                      = 23;

var ACT_BAN_USER                    = 24;

var ACT_GET_VIEW_STAT               = 25;

var ACT_GET_VIEW_VISITOR            = 26;

var ACT_REFRESH_DAILY_SENTENCE      = 27;

var ACT_REG_ACTIVE                  = 29;

var ACT_REG_USER                    = 28;

var ACT_HELP_LOGIN                  = 30;

var ACT_GET_USER_SEARCH             = 33;

var ACT_ADD_FEEDBACK                = 34;

var ACT_SHOW_EDIT =                 'show_edit'; 

var ACT_ADD_FAVORITE                = 'add_favorite';

var ACT_ADD_DOC_BAD                 = 'add_bad_doc';

var ACT_SHOW_ALL_FEEDBACK           = 38;

var ACT_GET_USER_RESULT             = 'get_user_result';

var ACT_VERIFY_SEARCH_SECURITY_CODE = 'verify_security_code';

var ACT_REFRESH_SESSION             = 'keep_session'; //42; 

var ACT_CLEAR_FAVORITE              = 'clear_favorite';

var ACT_SUPPLY_KEYWORD              = 'supply_keyword';

var ACT_CONVERT                     = 49; 

var ACT_ADD_DAILY                   = 50;

var ACT_SHOW_HIDE_COMMENT           = 51;

var ACT_PROCESS_GOOD_COMMENT        = 52;

var ACT_PROCESS_BAD_COMMENT         = 53;

var ACT_SHOW_HIDE_TOP_COMMENT       = 54;

var ACT_PROCESS_GOOD_DOC            = 55;

var ACT_PROCESS_BAD_DOC             = 56;

var ACT_INVITE_FRIEND               = 57;

// TODO: TINH - Hanh dong thay doi thuoc tinh active cua bang c_user

var ACT_CHANGE_STATUS				= 59;

var ACT_CHANGE_ISADMIN				= 60;



var ACT_GET_TRUSTIPS                = 63;

var ACT_TRUST_CLIENT_IP             = 64;

var ACT_YELLO_CLIENT_IP		    	= 65;

var ACT_EXPAND                      = 66;

var ACT_SHOW_HIDE_ENABLE            = 67;

var ACT_SHOW_HIDE_PREMIUM           = 68;

var ACT_GET_MEAN_QUESTION	        = 69;

var ACT_GET_CLUE_QUESTION	        = 70;

var ACT_GET_EXPLAIN_ANSWER	        = 71;

var ACT_GET_MEAN_ANSWER 	        = 72;

var ACT_GET_ALL_MEAN_ANSWER	        = 73;

var ACT_LIST_TEST                   = 75;

var ACT_CHECK_RESULT    	        = 76;

var ACT_RESEND                      = 77;

var ACT_GET_IP_LOCAL                = 78;

var ACT_REFRESH_SENDER_MESSAGE      = 79;

var ACT_SET_DOC_ERROR               = 80;

var ACT_ACCEPT_TO_HELLOCHAO         = 81;

var ACT_THEY_ARE_HARD               = 82;

var ACT_GET_FAQ_QUESTION            = 83;

var ACT_GET_FAQ_ANSWER	    		= 84;

var ACT_GET_MEDIA_LINK              = 87;

var ACT_CONVERT_FORUM_COMMENT_TO_ARTICLE = 'convert_forum_comment_to_article';

var ACT_SUPPLY_KEYWORD_ADMIN1       = 94;



var POPUP_ADD                       = 1;

var POPUP_EDIT                      = 2;



var RES_OPERATION_SUCCESS           = 1;

var RES_OPERATION_FAIL              = 0;



//ThanhViet added [20101013] copy from consts.php

var ACT_ADD_LIKE					= 'add_like';	

var ACT_GET_LIKE_BY_ID			    = 'get_like_by_id';

var ACT_GET_ALL_LIKE				= 'get_all_like';

var ACT_GET_USER_LIKE				= 'get_user_like';

var ACT_ADD_ARTICLE				    = 'add_article';	

var ACT_SHOW_ARTICLE_BY_ID		    = 'show_article_by_id';

var ACT_SHOW_ALL_ARTICLE			= 'show_all_artice';

var ACT_UPDATE_ARTICLE			    = 'update_article';

var ACT_DELETE_ARTICLE			    = 'delete_article';

var ACT_GET_CONTENT_ARTICLE		    = 'get_content_article';

var ADD_MODE                    = 1;

var EDIT_MODE                   = 2;

var LIMIT_INVITE_EMAIL          = 50;

var METHOD_GET                  = "GET";

var SEP_RESPONSE                = "&**&";

var SEP_RETURN                  = "(*.*)";

var SEP_EXAMPLE                 = "|^^|";

var DIVMSG_ID                   = "lblAlert";

var DIVMSG_CONTAINER            = "tblAlert";

var strCurrentPage              = "index.php";



var CONFIRM_DELETE_FAVORITE_DOC = "Bạn thật sự muốn xóa cặp câu sau khỏi danh sách câu yêu thích?<br><br>{0}";

var CONFIRM_DELETE_ADDED_DOC    = "Bạn thật sự muốn xóa cặp câu sau khỏi hệ thống?<br><br>{0}";

var CONFIRM_ADDED_FAVORITE_DOC  = "Bạn thật sự muốn chọn cặp câu sau làm câu yêu thích?<br><br>{0}";


// Title for dialogs
var DOC_BAD_TITLE               = "BÁO CÂU SAI";

var SHOW_DESCRIPTION_TITLE = "XEM GIẢI THÍCH THÊM";

var SEARCH_TITLE                = "TÌM KIẾM";

var FAVORITE_TITLE              = "CẶP CÂU YÊU THÍCH";

var KEYWORD_TITLE               = "HỖ TRỢ KEYWORD";

var PROFILE_TITLE               = "THÔNG TIN CÁ NHÂN";

var SYSTEM_TITLE_ERROR             = "CẶP CÂU ĐÃ THÊM";

var DOC_UPDATE_TITLE            = "THAY ĐỔi CẶP CÂU";

var MESSAGE_TITLE               = "TIN NHẮN";

var LOGIN_TITLE                 = "LOGIN";

var SYSTEM_TITLE                = "HỆ THỐNG";

var SYSTEM_TEST_TITLE_VN        = "HỆ THỐNG TEST";

var SYSTEM_TEST_TITLE_EN        = "SYSTEM TEST";



// Result message

var MSG_RES_OPERATION_FAIL      = "Thao tác không thành công. Vui lòng thử lại!";

var MSG_RES_OPERATION_SUCCESS   = "Thao tác thành công!";





// AJAX REQUEST MESSAGES

var MSG_AJAX_FETCHING           = "Fetching Data...";

var MSG_AJAX_EXPORTING          = "Exporting CSV...";

var MSG_AJAX_EDITING            = "Editing...";

var MSG_AJAX_DELETING           = "Deleting...";

var MSG_AJAX_ADDING             = "Adding...";

var MSG_AJAX_CHECKING           = "Checking...";

var MSG_AJAX_REBUILT            = "Rebuilting...";

var MSG_AJAX_FETCHING_VN        = "Đang xử lý...";

var MSG_AJAX_SENDING_VN         = "Đang xử lý...";

var MSG_AJAX_PROCESSING         = "Processing...";



// CONFIRM MESSAGE

var MSG_REBUILT                 = "Are you sure to rebuild all documents?";

var MSG_DELETEDOC               = "Are you sure to delete DocID ";

var MSG_APPROVE_ALL             = "Are you sure to approve all?";

var MSG_DELETE_USER             = "Are you sure to delete User ?";



// NOTICE MESSAGE

var MSG_INCORRECT_LANGUAGE_VN = "Nội dung tiếng Việt không phải là ngôn ngữ tiếng Việt. Bạn có muốn tiếp tục không?";
var MSG_INCORRECT_LANGUAGE_EN = "Nội dung tiếng Anh không phải là ngôn ngữ tiếng Anh. Bạn có muốn tiếp tục không?";
var MSG_ENTEXT_EMPTY            = "English can't be empty";

var MSG_VNTEXT_EMPTY            = "Vietnamese can't be empty";

var MSG_EDIT_ERROR              = "Cặp câu đã tồn tại trong hệ thống."

var MSG_EDIT_SUCCEED            = "Edit successful!";

var MSG_GETDATA                 = "Please input start record will get!";

var MSG_APPROVE_SUCCEED         = "Approve successful!"

var MSG_DELETE_SUCCEED          = "Delete successful!";

var MSG_DELETE_ERROR            = "Delete complete with errors!";

var MSG_SESSION_EXPIRE          = "Your session expired. Please login again!";

var MSG_SERVER_ERROR            = "Server error. Please try Again!";

var MSG_ADD_FAIL                = "Thao tác không thành công. Vui lòng thử lại!";

var MSG_ADD_SUCCEED             = "Add Succeed.";

var MSG_DOC_DUPLICATE           = "Cặp câu đã tồn tại trong hệ thống.";

var MSG_DOC_DUPLICATE_EN        = "Duplicate Content!";

var MSG_SEARCH_EMPTY            = "Please input the keyword!";

var MSG_SEARCH_CONTENT_VN       = "Vui lòng nhập từ khóa cần tìm!";

var MSG_EXAMPLE_CHECK_BLANK     = "{0} can't be blank!";

var MSG_ENCONTENT_NULL          = "English can't be blank.";

var MSG_VNCONTENT_NULL          = "Vietnamese can't be blank.";



var MSG_USERNAME_EMPTY          = "Username can't be empty.";

var MSG_PASSWORD_EMPTY_EN       = "Password can't be empty.";

var MSG_RETYPE_PASSWORD         = "Confirm Password can't be empty.";

var MSG_PASSWORD_MATCH          = "Password doesn't match.";

var MSG_PASSWORD_WRONG          = "Wrong password!";

var MSG_ACCOUNT_DISABLE         = "Your account was disabled by Admin!";

var MSG_ACCOUNT_USED            = "You were already login at another computer!";

var MSG_INVALID_VERIFICATION    = "Invalid verification code!";

var MSG_INVALID_USER            = "Invalid user or password!";

var MSG_UNKNOWN_LEVEL           = "Unknown user right!";

var MSG_USER_EXISTED            = "User {0} exists!";

var MSG_USER_DISABLE            = "Are you sure to disable user ";

var MSG_USER_ENABLE             = "Are you sure to enable user ";

var MSG_REFRESH_KEYWORD         = "Are you sure to refresh keywords?";

var MSG_REFRESH_DAILY_SENTENCE  = "Are you sure to refresh daily sentence?";

var MSG_NO_DUP                  = "There isn't any duplicates in this page!";

var MSG_DOC_NOT_EXIST           = "Cặp câu bạn yêu cầu không tồn tại.";



var MSG_EDIT_NON_EXISTENCE      = "You try to edit an deleted DocId!";

var MSG_PARENT_CLOSE            = "Parent window has been closed";



var MSG_ILE_CLI                 = "You made an ilegal click!";

var MSG_INVALID_IP              = "You've input an Invalid IP!";

// Message Reg User

var MSG_FULLNAME_EMPTY          = "Họ tên không được để trống.";

var MSG_EMAIL_EMPTY             = "Email không thể rỗng.";

var MSG_EMAIL_WRONG_FORMAT      = "Email nhập sai định dạng.";

var MSG_EMAIL_REFER_WRONG_FORMAT= "Email người giới thiệu nhập sai định dạng.";

var MSG_SEX                     = "Vui lòng chọn giới tính.";

var MSG_PASSWORD_EMPTY          = "Mật khẩu không được để trống.";

var MSG_PASSWORD_NOT_MATCH      = "Mật khẩu không khớp nhau.";

var MSG_PASSWORD_TOO_SIMPLE     = "Mật khẩu phải tối thiểu 6 kí tự.";

var MSG_DATE_ERROR              = "Ngày sinh không hợp lệ.";

var MSG_SEX_NULL                = "Bạn chưa chọn giới tính.";

var MSG_SEC_CODE_NULL           = "Bạn chưa nhập mã bảo mật.";

var MSG_AGREE                   = "Bạn phải đồng ý với điều khoản sử dụng hellochao để tiếp tục sử dụng hệ thống.";

var MSG_AGREE_CAMPAIGN          = "Bạn chưa click chọn vào các checkbox đồng ý các điều khoản của chương trình.";

// COMMENT MESSAGE

var MSG_COMMENT_CONTENT         = "Vui lòng nhập nội dung nhận xét!";

var MSG_COMMENT_NAME            = "Vui lòng nhập tên của bạn!";

var MSG_COMMENT_EMAIL_FORMAT    = "Vui lòng nhập địa chỉ email đúng định dạng!";

var MSG_COMMENT_EMAIL           = "Vui lòng nhập địa chỉ email!";



// ADMIN MESSAGE

var MSG_REFRESH_KW_SUCCEED      = "Refresh Keywords successful!";

var MSG_REFRESH_KW_FAIL         = "Refresh Keywords complete with errors!";

var MSG_REFRESH_KW_NORECORD     = "There isn't any record to refresh";

var MSG_DELETE_KEYWORD          = "Are you sure to delete selected keywords?";

var MSG_DELETE_KEYWORD_FAIL     = "Delete fail!";

var MSG_EN_DATE_ERROR           = "I haven't select a valid datetime.";



var MSG_REFRESH_DL_SUCCEED      = "Refresh daily-sentence successful!";

var MSG_REFRESH_DL_FAIL         = "Refresh keywords complete with errors!";



var MSG_ILEGAL_LOGIN            = "You don't have permission to access this page!";

var MSG_BAN_SUCCEED             = "Ban IP {0} Succeed";

var MSG_BAN_FAIL                = "Ban IP {0} Fail";



var MSG_DELETE_IP_YL            = "Are you sure to delete ip {0} from {1} ?";

var MSG_DELETE_IP_BL            = "Are you sure to delete ip {0} from {1} ?";

var MSG_DELETE_IP_SUCCEED       = "Delete IP {0} Succeed!";

var MSG_DELETE_IP_FAIL          = "Delete IP {0} Fail!";



// LOGIN PANEL MESSAGE

var MSG_LOGIN_BANNED            = "Tài khoản này đã bị khóa.";

var MSG_LOGIN_FAIL              = "[Email] và [Mật khẩu] không đúng.";



// TIMEOUT AJAX CALLBACK

var REQUEST_TIMEOUT             = 30000;

var MSG_TIMEOUT                 = "Không thể kết nối đến server. Vui lòng thử lại!";



var COMMENT_STATUS              = "Write your comment here...";

var COMMENT_STATUS_SMALL        = "Viết comment..";



var MSG_NO_SELECT               = "You haven't select any record to process!";



function addLoadEvent(func) 

{

  var oldonload = window.onload;

  if (typeof window.onload != 'function') 

  {

    window.onload = func;

  } 

  else 

  {

    window.onload = function() 

    {

      if (oldonload) 

      {

        oldonload();

      }

      func();

    }

  }

}



function addUnLoadEvent(func) 

{

  var oldunload = window.onunload;

  if (typeof window.onunload != 'function') 

  {

    window.onunload = func;

  } 

  else 

  {

    window.onunload = function() 

    {

      if (oldunload) 

      {

        oldunload();

      }

      func();

    }

  }

}



// show sticker

// Writen By : Thanh Dao

function showMessage(strMsg,idContainer,idInside,autoHide)

{

    if (!idContainer)

        idContainer = DIVMSG_CONTAINER;

    if (!idInside)

        idInside = DIVMSG_ID; 



    if(core.getObject(idInside) != null)

    {

        core.getObject(idInside).innerHTML = strMsg;

        core.getObject(idContainer).style.display = "";

        core.getObject(idContainer).style.visibility = "visible";

    }

    //ThanhViet added [20101208]

    /*

    if (typeof autoHide == "undefined") 

    {

        autoHide = true;

    }

    //autoHide = autoHide || true;

    if (autoHide==true) {

        setTimeout(function () 

        { 

            core.getObject(idContainer).style.display = "none";

            core.getObject(idContainer).style.visibility = "hidden";}

                        ,2000);    

    }

    */

}

// hide sticker

// Writen By : Thanh Dao

function killMessage(idContainer)

{

    if (!idContainer)

        idContainer = DIVMSG_CONTAINER;

        

    if(core.getObject(idContainer) != null)

    {

        core.getObject(idContainer).style.display = "none";

    }

}

// auto hide sticker

// Writen By : Thanh Viet

function autoHideMessage()

	{

	    setTimeout(function () 

                { 

                    killMessage();

                 },3000);

	}

function setSelectedSelectControlValue(strID, value)

{

    var sel = core.getObject(strID);

    

    if(sel != null)

    {

        if(value == null)

        {

            sel.selectedIndex = 0;

        }

    

        for(var i = 0; i < sel.length; i++)

        {

            if(sel[i].value == value)

            {

                sel.selectedIndex = i;

                break;

            }

        }

    }

}

// TODO: TINH - lay gia tri duoc chon cua doi tuong <select>

function getSelectSelctedValueofObject(obj) {

    if (obj != null) {

        for (var i = 0; i < obj.length; i++) {

            if (obj[i].selected) {

                return obj[i].value;

            }

        }

    }



    return false;

}

// get value in current radio control

// Writen By : Thanh Dao

function getRadioCheckedValue(strChbxID) {

    var obj = document.getElementsByName(strChbxID);



    if (obj != null) {

        for (var i = 0; i < obj.length; i++) {

            if (obj[i].checked) {

                return obj[i].value;

            }

        }

    }



    return false;

}

// get value in current select control

// Writen By : Thanh Dao

function getSelectCheckedValue(strChbxID) {

    var obj = core.getObject(strChbxID);

    var childArray = obj.childNodes;

    if (obj != null) {

        for(i = 0; i < childArray.length; i++){

            if (childArray[i].selected) {

                 return childArray[i].value;

            }

        }

    }



    return false;

}



function setAction(intAct)

{

    core.getObject("act").value = intAct;

}



function setUnsetCheckAll(strFormID, strChbxID, strChbxAllID) {

    frm = core.getObject(strFormID);

    var isCheckedAll = true;

    //	

    for (var i = 0; i < frm.elements.length; i++) {

        var element = frm.elements[i];

        //

        if (element.id == strChbxID && element.type == 'checkbox') {

            if (!element.checked) {

                isCheckedAll = false;

            }

        }

    }

    //

    core.getObject(strChbxAllID).checked = isCheckedAll;



    return isCheckedAll;

}



function select_uncheck_AllSelect(strFormID, chbxID, bln) {

    var frm = core.getObject(strFormID);

    var ibln=0;

    //	 

    if (bln == true) 

            ibln=1;           

        else

            ibln=2;

    for (var i = 0; i < frm.elements.length; i++) 

    {

        var element = frm.elements[i];

        if (element.id == chbxID && element.type == "select-one") 

        //if (element.type == "select-one") 

        {

            element.value = ibln;

            

        }        

    }

}



function select_uncheck_AllCheckboxs(strFormID, chbxID, bln) {

    var frm = core.getObject(strFormID);

    //

    for (var i = 0; i < frm.elements.length; i++) {

        var element = frm.elements[i];

        //

        if (element.id == chbxID && element.type == "checkbox") {

            element.checked = bln;

        }        

    }

}



// format string by parameter {0} {1}

// Writen By : Thanh Dao
// Reuse - R
function stringFormat(strQuery, arrArguments)
	{
		var intCount = 0;

		var i;

		var strResult="";

		    for (i=0;i<strQuery.length;i++)

		    {

		        if (intCount==arrArguments.length)

		            break;

		        try{

		        if (arrArguments[i].substr(0,2)=="EN")

		        {    arrArguments[i]= "English Example "+arrArguments[i].substr(2);}

		        if (arrArguments[i].substr(0,2)=="VN")

		        {    arrArguments[i]= "Vietnamese Example "+arrArguments[i].substr(2);}

		        }catch(e){}

		        var strReplace = "{" + intCount + "}";

		        var strFind="";

		        if (strQuery.substr(i,1)=="{")

		        {

		            for (var j=i;j<strQuery.length;j++)

		                {

		                    strFind += strQuery.substr(j,1);

		                    if (strQuery.substr(j,1)=="}")

		                        {

		                            break;

		                        }

		                }

		            if (strFind==strReplace)

		            {

		                strResult = strQuery.substr(0,i)+arrArguments[intCount]+strQuery.substr(j+1);

		                strQuery = strResult;

		                intCount++;

		            }		        

		        }

	        }

		return strResult;

	}

// check pop up form has any blank examples

// Writen By : Thanh Dao

function checkBlankExamples(strFormID)

{

    var frm = core.getObject(strFormID);

    //	    

    var arrElements = frm.getElementsByTagName("tr");

    for (var i = 0; i < arrElements.length; i++) 

    {

        var element = arrElements[i];

        //

        if (element.id.substr(0,7)=="divDesc" && element.style.display=="")

          {

            var inputbox1 = core.getObject("txtDescEN"+element.id.substr(9));

            var inputbox2 = core.getObject("txtDescVN"+ element.id.substr(9));

            if (core.trim(inputbox1.value)=="" && core.trim(inputbox2.value)=="")

            {

                i=i+2;

                var arrArguments =[];

                arrArguments[0] = inputbox1.id.substr(7);

                var strAlert = stringFormat(MSG_EXAMPLE_CHECK_BLANK,arrArguments);

                alert(strAlert);

                return false;

            }

            else if (core.trim(inputbox1.value)=="" && core.trim(inputbox2.value)!="")

            {   inputbox1.focus();

                var arrArguments =[];

                arrArguments[0] = inputbox1.id.substr(7);

                var strAlert = stringFormat(MSG_EXAMPLE_CHECK_BLANK,arrArguments);

                alert(strAlert);

                return false;

            }

            else if (core.trim(inputbox2.value)=="" && core.trim(inputbox1.value)!="")

            {   inputbox2.focus();

                var arrArguments =[];

                arrArguments[0] = inputbox2.id.substr(7);

                var strAlert = stringFormat(MSG_EXAMPLE_CHECK_BLANK,arrArguments);

                alert(strAlert);

                return false;

            }

          }

    }

    return true;

}

// check match password

// Writen By : Thanh Dao

function checkMatch(strPassword, strConfirmPassword)

{

    if ( strPassword !== "" || strConfirmPassword!=="")

        if (strPassword==strConfirmPassword)

            return false;

    return true;

}

// check blank in string

// Writen By : Thanh Dao

function checkBlank(strString)

{

    if (core.trim(strString)=="")

        return true;

    return false;

}



var __isIE =  navigator.appVersion.match(/MSIE/);

var __userAgent = navigator.userAgent;

var __isFireFox = __userAgent.match(/firefox/i);

var __isFireFoxOld = __isFireFox && 

   (__userAgent.match(/firefox\/2./i) || __userAgent.match(/firefox\/1./i));

var __isFireFoxNew = __isFireFox && !__isFireFoxOld;



function __parseBorderWidth(width) {

    var res = 0;

    if (typeof(width) == "string" && width != null 

                && width != "" ) {

        var p = width.indexOf("px");

        if (p >= 0) {

            res = parseInt(width.substring(0, p));

        }

        else {

             //do not know how to calculate other 

             //values (such as 0.5em or 0.1cm) correctly now

             //so just set the width to 1 pixel

            res = 1; 

        }

    }

    return res;

}



//returns border width for some element

function __getBorderWidth(element) {

    var res = new Object();

    res.left = 0; res.top = 0; res.right = 0; res.bottom = 0;

    if (window.getComputedStyle) {

        //for Firefox

        var elStyle = window.getComputedStyle(element, null);

        res.left = parseInt(elStyle.borderLeftWidth.slice(0, -2));  

        res.top = parseInt(elStyle.borderTopWidth.slice(0, -2));  

        res.right = parseInt(elStyle.borderRightWidth.slice(0, -2));  

        res.bottom = parseInt(elStyle.borderBottomWidth.slice(0, -2));  

    }

    else {

        //for other browsers

        res.left = __parseBorderWidth(element.style.borderLeftWidth);

        res.top = __parseBorderWidth(element.style.borderTopWidth);

        res.right = __parseBorderWidth(element.style.borderRightWidth);

        res.bottom = __parseBorderWidth(element.style.borderBottomWidth);

    }

   

    return res;

}



//returns absolute position of some element within document

function getElementAbsolutePos(element) {

    var res = new Object();

    res.x = 0; res.y = 0;

    if (element !== null) {

        res.x = element.offsetLeft;

        res.y = element.offsetTop;

        

        var offsetParent = element.offsetParent;

        var parentNode = element.parentNode;

        var borderWidth = null;



        while (offsetParent != null) {

            res.x += offsetParent.offsetLeft;

            res.y += offsetParent.offsetTop;

            

            var parentTagName = offsetParent.tagName.toLowerCase();    



            if ((__isIE && parentTagName != "table") || 

                (__isFireFoxNew && parentTagName == "td")) {            

                borderWidth = __getBorderWidth(offsetParent);

                res.x += borderWidth.left;

                res.y += borderWidth.top;

            }

            

            if (offsetParent != document.body && 

                offsetParent != document.documentElement) {

                res.x -= offsetParent.scrollLeft;

                res.y -= offsetParent.scrollTop;

            }



            //next lines are necessary to support FireFox problem with offsetParent

               if (!__isIE) {

                while (offsetParent != parentNode && parentNode !== null) {

                    res.x -= parentNode.scrollLeft;

                    res.y -= parentNode.scrollTop;

                    

                    if (__isFireFoxOld) {

                        borderWidth = __getBorderWidth(parentNode);

                        res.x += borderWidth.left;

                        res.y += borderWidth.top;

                    }

                    parentNode = parentNode.parentNode;

                }    

            }



            parentNode = offsetParent.parentNode;

            offsetParent = offsetParent.offsetParent;

        }

    }

    return res;

}

//----------- ENCODE HTML CHARACTER ----------------------

function encodeHTML(strString)

{

    var strEncode = htmlentities(strString,"ENT_QUOTES");

    var arrCharList = ("ò ó ô õ Ò Ó Ô Õ ù ú Ù Ú à á â ã À Á Â Ã è é	ê È É Ê ì í Ì Í").split(" ");

	var arrBackward = ("&#242; &#243; &#244; &#245; &#210; &#211; &#212; &#213; &#249; &#250; &#249; &#250; &#217; &#218; &#224; &#225; &#226; &#227; &#192; &#193; &#194; &#195; &#232; &#233; &#234; &#200; &#201; &#202; &#236; &#237; &#204; &#205;").split(" ");

	var arrFriendLy = ("&ograve; &oacute; &ocirc; &otilde; &Ograve; &Oacute; &Ocirc; &Otilde; &ugrave; &uacute; &Ugrave; &Uacute; &agrave; &aacute; &acirc; &atilde; &Agrave; &Aacute; &Acirc; &Atilde; &egrave; &eacute; &ecirc; &Egrave; &Eacute; &Ecirc; &igrave; &iacute; &Igrave; &Iacute;").split(" ");

	var countchar = arrCharList.length;

	for (var i=0;i<countchar;i++)

	{

	    var rep = arrFriendLy[i];

		strEncode = strEncode.replace(/rep/gi,arrCharList[i]);

	}

    return strEncode;

}

function htmlentities (string, quote_style) {

    var histogram = {}, symbol = '', tmp_str = '', entity = '';

    tmp_str = string.toString();

    

    if (false === (histogram = get_html_translation_table('HTML_ENTITIES', quote_style))) {

        return false;

    }

    histogram["'"] = '&#039;';

    for (symbol in histogram) {

        entity = histogram[symbol];

        tmp_str = tmp_str.split(symbol).join(entity);

    }

    

    return tmp_str;

}







function get_html_translation_table(table, quote_style) {

    var entities = {}, histogram = {}, decimal = 0, symbol = '';

    var constMappingTable = {}, constMappingQuoteStyle = {};

    var useTable = {}, useQuoteStyle = {};

    

    // Translate arguments

    constMappingTable[0]      = 'HTML_SPECIALCHARS';

    constMappingTable[1]      = 'HTML_ENTITIES';

    constMappingQuoteStyle[0] = 'ENT_NOQUOTES';

    constMappingQuoteStyle[2] = 'ENT_COMPAT';

    constMappingQuoteStyle[3] = 'ENT_QUOTES';



    useTable       = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';

    useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';



    if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {

        throw new Error("Table: "+useTable+' not supported');

        // return false;

    }



    if (useTable === 'HTML_ENTITIES') {

        entities['160'] = '&nbsp;';

        entities['161'] = '&iexcl;';

        entities['162'] = '&cent;';

        entities['163'] = '&pound;';

        entities['164'] = '&curren;';

        entities['165'] = '&yen;';

        entities['166'] = '&brvbar;';

        entities['167'] = '&sect;';

        entities['168'] = '&uml;';

        entities['169'] = '&copy;';

        entities['170'] = '&ordf;';

        entities['171'] = '&laquo;';

        entities['172'] = '&not;';

        entities['173'] = '&shy;';

        entities['174'] = '&reg;';

        entities['175'] = '&macr;';

        entities['176'] = '&deg;';

        entities['177'] = '&plusmn;';

        entities['178'] = '&sup2;';

        entities['179'] = '&sup3;';

        entities['180'] = '&acute;';

        entities['181'] = '&micro;';

        entities['182'] = '&para;';

        entities['183'] = '&middot;';

        entities['184'] = '&cedil;';

        entities['185'] = '&sup1;';

        entities['186'] = '&ordm;';

        entities['187'] = '&raquo;';

        entities['188'] = '&frac14;';

        entities['189'] = '&frac12;';

        entities['190'] = '&frac34;';

        entities['191'] = '&iquest;';

        entities['192'] = '&Agrave;';

        entities['193'] = '&Aacute;';

        entities['194'] = '&Acirc;';

        entities['195'] = '&Atilde;';

        entities['196'] = '&Auml;';

        entities['197'] = '&Aring;';

        entities['198'] = '&AElig;';

        entities['199'] = '&Ccedil;';

        entities['200'] = '&Egrave;';

        entities['201'] = '&Eacute;';

        entities['202'] = '&Ecirc;';

        entities['203'] = '&Euml;';

        entities['204'] = '&Igrave;';

        entities['205'] = '&Iacute;';

        entities['206'] = '&Icirc;';

        entities['207'] = '&Iuml;';

        entities['208'] = '&ETH;';

        entities['209'] = '&Ntilde;';

        entities['210'] = '&Ograve;';

        entities['211'] = '&Oacute;';

        entities['212'] = '&Ocirc;';

        entities['213'] = '&Otilde;';

        entities['214'] = '&Ouml;';

        entities['215'] = '&times;';

        entities['216'] = '&Oslash;';

        entities['217'] = '&Ugrave;';

        entities['218'] = '&Uacute;';

        entities['219'] = '&Ucirc;';

        entities['220'] = '&Uuml;';

        entities['221'] = '&Yacute;';

        entities['222'] = '&THORN;';

        entities['223'] = '&szlig;';

        entities['224'] = '&agrave;';

        entities['225'] = '&aacute;';

        entities['226'] = '&acirc;';

        entities['227'] = '&atilde;';

        entities['228'] = '&auml;';

        entities['229'] = '&aring;';

        entities['230'] = '&aelig;';

        entities['231'] = '&ccedil;';

        entities['232'] = '&egrave;';

        entities['233'] = '&eacute;';

        entities['234'] = '&ecirc;';

        entities['235'] = '&euml;';

        entities['236'] = '&igrave;';

        entities['237'] = '&iacute;';

        entities['238'] = '&icirc;';

        entities['239'] = '&iuml;';

        entities['240'] = '&eth;';

        entities['241'] = '&ntilde;';

        entities['242'] = '&ograve;';

        entities['243'] = '&oacute;';

        entities['244'] = '&ocirc;';

        entities['245'] = '&otilde;';

        entities['246'] = '&ouml;';

        entities['247'] = '&divide;';

        entities['248'] = '&oslash;';

        entities['249'] = '&ugrave;';

        entities['250'] = '&uacute;';

        entities['251'] = '&ucirc;';

        entities['252'] = '&uuml;';

        entities['253'] = '&yacute;';

        entities['254'] = '&thorn;';

        entities['255'] = '&yuml;';

    }



    if (useQuoteStyle !== 'ENT_NOQUOTES') {

        entities['34'] = '&quot;';

    }

    if (useQuoteStyle === 'ENT_QUOTES') {

        entities['39'] = '&#39;';

    }

    entities['60'] = '&lt;';

    entities['62'] = '&gt;';



    // ascii decimals for better compatibility

    //entities['38'] = '&amp;';



    // ascii decimals to real symbols

    for (decimal in entities) {

        symbol = String.fromCharCode(decimal);

        histogram[symbol] = entities[decimal];

    }

    

    return histogram;

}

//-------------------------------------------------



// Simulates PHP's date function

Date.prototype.format = function(format) {

	var returnStr = '';

	var replace = Date.replaceChars;

	for (var i = 0; i < format.length; i++) {

		var curChar = format.charAt(i);

		if (replace[curChar]) {

			returnStr += replace[curChar].call(this);

		} else {

			returnStr += curChar;

		}

	}

	return returnStr;

};

Date.replaceChars = {

	shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],

	longMonths: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],

	shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],

	longDays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],

	

	// Day

	d: function() { return (this.getDate() < 10 ? '0' : '') + this.getDate(); },

	D: function() { return Date.replaceChars.shortDays[this.getDay()]; },

	j: function() { return this.getDate(); },

	l: function() { return Date.replaceChars.longDays[this.getDay()]; },

	N: function() { return this.getDay() + 1; },

	S: function() { return (this.getDate() % 10 == 1 && this.getDate() != 11 ? 'st' : (this.getDate() % 10 == 2 && this.getDate() != 12 ? 'nd' : (this.getDate() % 10 == 3 && this.getDate() != 13 ? 'rd' : 'th'))); },

	w: function() { return this.getDay(); },

	z: function() { return "Not Yet Supported"; },

	// Week

	W: function() { return "Not Yet Supported"; },

	// Month

	F: function() { return Date.replaceChars.longMonths[this.getMonth()]; },

	m: function() { return (this.getMonth() < 11 ? '0' : '') + (this.getMonth() + 1); },

	M: function() { return Date.replaceChars.shortMonths[this.getMonth()]; },

	n: function() { return this.getMonth() + 1; },

	t: function() { return "Not Yet Supported"; },

	// Year

	L: function() { return "Not Yet Supported"; },

	o: function() { return "Not Supported"; },

	Y: function() { return this.getFullYear(); },

	y: function() { return ('' + this.getFullYear()).substr(2); },

	// Time

	a: function() { return this.getHours() < 12 ? 'am' : 'pm'; },

	A: function() { return this.getHours() < 12 ? 'AM' : 'PM'; },

	B: function() { return "Not Yet Supported"; },

	g: function() { return this.getHours() % 12 || 12; },

	G: function() { return this.getHours(); },

	h: function() { return ((this.getHours() % 12 || 12) < 10 ? '0' : '') + (this.getHours() % 12 || 12); },

	H: function() { return (this.getHours() < 10 ? '0' : '') + this.getHours(); },

	i: function() { return (this.getMinutes() < 10 ? '0' : '') + this.getMinutes(); },

	s: function() { return (this.getSeconds() < 10 ? '0' : '') + this.getSeconds(); },

	// Timezone

	e: function() { return "Not Yet Supported"; },

	I: function() { return "Not Supported"; },

	O: function() { return (this.getTimezoneOffset() < 0 ? '-' : '+') + (this.getTimezoneOffset() / 60 < 10 ? '0' : '') + (this.getTimezoneOffset() / 60) + '00'; },

	T: function() { return "Not Yet Supported"; },

	Z: function() { return this.getTimezoneOffset() * 60; },

	// Full Date/Time

	c: function() { return "Not Yet Supported"; },

	r: function() { return this.toString(); },

	U: function() { return this.getTime() / 1000; }

};



// Trap CTRL+Q hotkey

var isCtrl = false; 

document.onkeyup=funckeyup;

function funckeyup(e)

{ 

    if(window.event)

    {

        key = window.event.keyCode; //IE

        if(key==17)

            isCtrl = false;

    }

    else

    {

        key = e.which; //firefox

        if(key==17)

            isCtrl = false;

    }

} 



document.onkeydown=funckeydown;

function funckeydown(e)

{ 

	if(window.event)

    {

        key = window.event.keyCode; //IE

        if(key == 17)

            {  isCtrl=true;}

            

        if(key==81 && isCtrl == true)

        {

		    if (strCurrentPage!="index.php")

			{    

			    if (confirm("Are you sure to logout?"))

			        {window.location.href = "logout.php";}

			    

			}

		}

    }

    else

    {

        key = e.which; //firefox

        if(key == 17)

            {  isCtrl=true;}

        if(key==81 && isCtrl == true)

        {

		    if (strCurrentPage!="index.php")

			{   

			    if (confirm("Are you sure to logout?"))

			        {window.location.href = "logout.php"; }

			}

        }

    }

} 

function addslashes( str ) {

    return (str+'').replace(/([\\"'])/g, "\\$1").replace(/\u0000/g, "\\0");

}



function removeslashes( strInString)

{

    return strInString.replace(/\\/gi,"");

}



function html_entity_decode( string, quote_style ) 

{

    var hash_map = {}, symbol = '', tmp_str = '', entity = '';

    tmp_str = string.toString();

    

    if (false === (hash_map = this.get_html_translation_table('HTML_ENTITIES', quote_style))) {

        return false;

    }



    for (symbol in hash_map) {

        entity = hash_map[symbol];

        tmp_str = tmp_str.split(entity).join(symbol);

    }

    tmp_str = tmp_str.split('&#039;').join("'");

    

    return tmp_str;

}

// decode html

function decodeHTML(string)

{

    return html_entity_decode(string,"ENT_QUOTES");

}

// add slash and encode html

function scriptdata(strString)

{

    return encodeHTML(addslashes(strString));

}

// remove enter char

function removeCR( strInString)

{

    var resultString="";

    for (var j=0;j<strInString.length;j++)

    {

        if (strInString.substr(j,1)=="\\" && strInString.substr(j+1,1)=="r")

        {

            j = j+1;

        }

        else

        {

            resultString += strInString.substr(j,1);

        }

    }

    if (resultString==strInString)

    {   return strInString.replace(/\r/gi,"");}

    return resultString;

}



// encode to escape special character

// Writen by Thanh Dao

function urlencode(str) 

{

    if (document.all)

    {

        var resultTmp = encodeURI(str);

        // replace $&+,/:;=?@

        resultTmp = resultTmp.replace(/&/gi,'%26').replace(/#/gi,'%23').replace(/=/gi,'%3D').replace(/\?/gi,'%3F').replace(/\+/gi,'%2B');

        return resultTmp;

    }

    

    var hexStr = function (dec) {

        return '%' + dec.toString(16).toUpperCase();

    };



    var ret = '',

            unreserved = /[\w.-]/, // A-Za-z0-9_.- // Tilde is not here for historical reasons; to preserve it, use rawurlencode instead

            permitList = /[&=%?]/;///[$&+,:;=?@]/;

    str = (str+'').toString();



    for (var i = 0, dl = str.length; i < dl; i++) {

        var ch = str.charAt(i);         

        if (!permitList.test(ch)) {

            // Get /n or /r

            var code = str.charCodeAt(i);

            if (code == 13)

            {

                ret += "%0D";//ch;

            }else if(code == 10){

                ret += "%0A";//ch;                

            }

            else if(code == 43){

                ret += "%2B";//ch;                

            }

            else if(code == 35){

                ret += "%23";//ch;                

            }else{

                ret += ch;

            }

        }

        else {

            var code = str.charCodeAt(i);

            // Reserved assumed to be in UTF-8, as in PHP

            if (code === 32) {

                ret += '+'; // %20 in rawurlencode

            }

            else if (code < 128) { // 1 byte

                ret += hexStr(code);

            }

            else if (code >= 128 && code < 2048) { // 2 bytes

                ret += hexStr((code >> 6) | 0xC0);

                ret += hexStr((code & 0x3F) | 0x80);

            }

            else if (code >= 2048 && code < 65536) { // 3 bytes

                ret += hexStr((code >> 12) | 0xE0);

                ret += hexStr(((code >> 6) & 0x3F) | 0x80);

                ret += hexStr((code & 0x3F) | 0x80);

            }

            else if (code >= 65536) { // 4 bytes

                ret += hexStr((code >> 18) | 0xF0);

                ret += hexStr(((code >> 12) & 0x3F) | 0x80);

                ret += hexStr(((code >> 6) & 0x3F) | 0x80);

                ret += hexStr((code & 0x3F) | 0x80);

            }

        }

    }

    return ret;

}



function closePageSignal()

{

    var ajax = new Ajax();	

	ajax.SendRequestToServer("logout.php", "act=" + ACT_LOGOUT, null, false);

}

// check valid ip address

// Writen by Thanh Dao



function validateIP(strIP)

{

    var arrResult = strIP.split('.');

    if (arrResult.length==4)

    {

        for (var i=0;i<arrResult.length;i++)

        {

            if (core.trim(arrResult[i])=="" || arrResult[i].length>3 || arrResult[i]>255 || arrResult[i]<0)

            {

                return false;

            }

        }

        return true;

    }

    return false;

}

// convert pixel string to int

function pixelToInt(strpx)

{

    return strpx.substr(0,strpx.length-2);

}

// check is valid date format

function isDateValue(Str) {

    var V, DObj = NaN;

    V = Str.match(/^(\d{4})-(\d\d)-(\d\d)$/);

    if (V) {

        V = (DObj = new Date(V[1], --V[2], V[3])).getMonth() == V[2];

    }

    return [!!V];

}

// set style element

// Writen by Thanh Dao



function rzCC(s){

   for(var exp=/-([a-z])/; 

       exp.test(s); 

       s=s.replace(exp,RegExp.$1.toUpperCase()));

   return s;

 }



 function _setStyle(element, declaration) {

   if (declaration.charAt(declaration.length-1)==';')

     declaration = declaration.slice(0, -1);

   var k, v;

   var splitted = declaration.split(';');

   for (var i=0, len=splitted.length; i<len; i++) {

      k = rzCC(splitted[i].split(':')[0]);

      v = splitted[i].split(':')[1];

      eval("element.style."+k+"='"+v+"'");



   }

 }

 

 function push_message_error(strError)

 {

    return "<li>" + strError + "</li>";

 }



function showInputCommentStatus(control,message,css)

{

    var objControl = core.getObject(control);

    if (objControl && core.trim(objControl.value)=='') 

    {    

        objControl.value = message;

        objControl.className = css;

    }

}



function hideInputCommentStatus(control,message,css)

{

    var objControl = core.getObject(control);

    if (objControl && core.trim(objControl.value)==message) 

    {

        objControl.value = "";

        objControl.className = css;

    }

}





function SetCookie( name, value, expires, path, domain, secure )

{

    var today = new Date();

    today.setTime( today.getTime() );

    if ( expires>0 )

    {

        expires = expires * 1000 * 60 * 60 * 24;

    }

    var expires_date = new Date( today.getTime() + (expires) );

    document.cookie = name + "=" + escape( value ) +

    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +

    ( ( path ) ? ";path=/":"") +

    ( ( domain ) ? ";domain=" + domain : "" ) +

    ( ( secure ) ? ";secure" : "" );

}



function SetCookieAll(name,value,expires)

{

    SetCookie(name,value,expires);

}

function eraseCookieAll(name)

{

    SetCookie(name,null,-1);

}



function screenCover(msg,divDialog,objCover)

{

    if (objCover==null)

    {

        objCover = document.createElement("div");

        objCover.innerHTML = "<div class=\"transparent_on\" style=\"border:2px;position:absolute;background-color:#323232;display:none\"></div>";

        objCover.id = "divCover";

    }

	objCover.style.left = 0;

	objCover.style.top  = 0;

	objCover.style.width = "100%";

	objCover.style.height = "100%";

	objCover.style.minHeight = "100%";

	objCover.style.display = "block";

	if (divDialog==null)

	{

        //showDialog('Error',msg,'error');	

    }

    else

    {

	    divDialog.style.display = "block";

	    divDialog.style.top = core.getInsideWindowHeight()/2-core.getObjectHeight(divDialog.id)/2;

	    divDialog.style.left = core.getInsideWindowWidth()/2-core.getObjectWidth(divDialog.id)/2;

    }

}



var i = 0,timer;	

function screenUnCover(objCover,divDialog,divBlink)

{

    if (objCover==null)

    {

        return;

        //objCover = core.getObject("");

    }

	objCover.style.display = "none";

	divDialog.style.display = "none";

	document.getElementsByTagName('html')[0].style.overflow = "auto";

	if (divBlink)

	{

	    timer = setInterval("blink("+divBlink.id+")", 500);

	}

}



function blink(obj) 

{

    if (i<5) 

    {

        if (i%2 == 0) 

        { 

            obj.setAttribute("class","div-login_blink");

        } 

        else 

        {

            obj.setAttribute("class","div-login");

        }

    } 

    else 

    {

        obj.setAttribute("class","div-login");

        clearInterval(timer);

        i = 0;

    }

    i++;

}



// Xu ly thong tin trong header

// banValue, expireSesValue, spamFailValue: cac gia tri tu server response ve

// checkBan, checkExpireSes, checkSpamFail: Muon check thang nao thi cho no bang "true", nguoc lai bang "false"

// Return: true (good header), false (bad header).

function headerProcessing(banValue, expireSesValue, spamFailValue, checkBan, checkExpireSes, checkSpamFail)

{

    // Check for banValue

    if (checkBan)

    {

        if (banValue > 0)

        {

            window.location.href='antidos.php?txtAccess=' + banValue;

            return false;

        }

    }

    

    // Check for expireSesValue

    if (checkExpireSes)

    {

        if (expireSesValue == "1")

        {

            sessionExpireProcessing();

            // Xu ly yeu cau nguoi dung login lai

            return false;

        }        

    }

    

    // Check for spamFailValue

    if (checkSpamFail)

    {

        if (spamFailValue == "1")

        {

            //alert("xu ly spam fail");

            // Xu ly truong hop nay

            return false;

        }

    }

    return true;

}

/*

* Xu ly thong tin trong header

* 

* @param array arrHeader mang cac gia tri tu server response ve

* @param array arrCheckHeader mang cac gia tri bool cho biet check phan tu nao trong arrHeader, "true" check, "false" khong check

* Return: true (good header), false (bad header).

* @author TinhDoan added [20100524]

*

*/

function core.headerProcessingArr(arrHeader, arrCheckHeader)

{

    // Check for banValue

    if (arrCheckHeader[0])

    {

        if (arrHeader["h1"] > 0)

        {

            window.location.href='antidos.php?txtAccess=' + arrHeader["h1"];

            return false;

        }

    }

    

    // Check for expireSesValue

    if (arrCheckHeader[1])

    {

        if (arrHeader["h2"] == "1")

        {

            sessionExpireProcessing();

            // Xu ly yeu cau nguoi dung login lai

            return false;

        }        

    }

    

    // Check for spamFailValue

    if (arrCheckHeader[2])

    {

        if (arrHeader["h3"] == "1")

        {

            //alert("xu ly spam fail");

            // Xu ly truong hop nay

            return false;

        }

    }

    return true;

}



function sessionExpireProcessing()

{

    dlgBox.showDialog(LOGIN_TITLE,"Bạn chưa login. Vui lòng login!","sessionExpireProcessing_OK()",null,2);

	//core.getObject("divLogin").innerHTML = "<form method=\"post\"><div id=\"tblAlert\" style=\"display:none\" align=\"center\"><table style=\"padding:0px;margin:0px\"><tr><td><div id=\"nifty\"><b class=\"rtop\"><b class=\"r1\"></b><b class=\"r2\"></b><b class=\"r3\"></b><b class=\"r4\"></b></b><div id=\"lblAlert\" align=\"center\" style=\"margin-left:10px;margin-right:10px;\" class=\"alert-msg-normal\"></div><b class=\"rbottom\"><b class=\"r4\"></b><b class=\"r3\"></b><b class=\"r2\"></b><b class=\"r1\"></b></b></div></td></tr></table></div><div style=\"width:52px;float:left;height:16px;padding-top:3px;margin-bottom:2px;cursor:default;\">Email</div> <div style=\"float:left;width:158px;margin-bottom:2px\"><input style=\"height:15px;width:100%\" id=\"email\" type=\"text\" value=\"\" /></div><div class=\"clearfix\" style=\"width:52px;float:left;height:16px;padding-top:3px;margin-bottom:2px;cursor:default;\">Mật khẩu</div> <div style=\"float:left;width:158px;margin-bottom:2px\"><input style=\"height:15px;width:100%\" id=\"cpassword\" type=\"Password\" value=\"\" /></div><div class=\"clearfix\" style=\"height:2px\">&nbsp;</div><div style=\"margin-bottom:5px;\">Nhập mã xác nhận</div><div style=\"float:left;margin-left:0px\"><img id=\"imgSecChar\" src=\"capcha.php?type=0\" /></div><div style=\"float:left;width:20px;\">&nbsp;</div><div style=\"float:left;margin-top:-1px;\"><input id=\"txtCode\" type=\"text\" maxlength=5 style=\"width:90px;height:16px;\" /></div><div class=\"clearfix\" style=\"height:2px\">&nbsp;</div><div style=\"float:left;width:208px;margin-left:5px;margin-top:1px;\"><div style=\"float:left\"><input type=\"checkbox\" id=\"chkRemember\" style=\"margin-left:0\" /></div><div style=\"float:left;margin-top:2px;cursor:default;\" onclick=\"document.getElementById('chkRemember').checked=!document.getElementById('chkRemember').checked\">Tự động đăng nhập</div><div style=\"float:right\"><input class=\"button-style button-submit\" type=\"button\" value=\"Login\" style=\"width:43px;height:20px;padding:0;margin:0px;margin-top:-1px;\" onclick=\"login()\" /></div></div><div class=\"clearfix\" style=\"height:2px\">&nbsp;</div><div class=\"bd_t1 pdg_t5\" align=\"center\"> <a href=\"user.php?d=30\" style=\"text-decoration:none\">Trợ giúp Login</a>| <a href=\"user.php\" style=\"font-color:#4866de;text-decoration:none\"><font color=\"#4866de\">Đăng ký</font></a></div></form>";

	core.getObject("divLogin").innerHTML = "<div class=\"hr_title\"></div><div class=\"title\">Đăng nhập</div><div class=\"frame_bgc\"><form method=\"post\" onsubmit=\"login();return false;\"><div id=\"tblAlertLogin\" style=\"display: none;\" align=\"center\"><table style=\"padding: 0px; margin: 0px;\">  <tbody><tr><td><div id=\"nifty\"><b class=\"rtop\"><b class=\"r1\"></b><b class=\"r2\"></b><b class=\"r3\"></b><b class=\"r4\"></b></b><div id=\"lblAlertLogin\" style=\"margin-left: 10px; margin-right: 10px;\" class=\"alert-msg-small\" align=\"center\"></div><b class=\"rbottom\"><b class=\"r4\"></b><b class=\"r3\"></b><b class=\"r2\"></b><b class=\"r1\"></b></b></div></td>  </tr></tbody></table></div><div class=\"divinline pdg_t3\"><label for=\"email\">Email</label></div> <div class=\"divinline div_alg_r wdh70p\"><input style=\"height: 16px; width: 100%;\" id=\"email\" value=\"\" type=\"text\"></div><div class=\"clearfix hgt5\">&nbsp;</div><div class=\"divinline pdg_t3\">Mật khẩu</div> <div class=\"divinline div_alg_r wdh70p\"><input style=\"height: 16px; width: 100%;\" id=\"cpassword\" value=\"\" type=\"Password\"></div><div class=\"clearfix hgt5\">&nbsp;</div><div class=\"divinline pdg_t3\"><input id=\"chkRemember\" type=\"checkbox\"></div><div class=\"divinline pdg_t5\"><label for=\"chkRemember\">Tự động login lần sau</label></div><div class=\"divinline flt-r\"><input class=\"button-style button-submit\" value=\"Log in\" type=\"submit\"></div><div class=\"clearfix hgt3\">&nbsp;</div><div class=\"bd_t1 pdg_t5\" align=\"center\"> <a href=\"javascript:helpLogin_login();\" class=\"m_link\">Trợ giúp Login</a>| <a href=\"javascript:regUser_login();\" class=\"m_link\">Đăng ký</a></div></form></div>";

	

}

function sessionExpireProcessing_OK()

{

    core.getObject("email").focus();

}



// Get innerText of object

// Writen by Thanh Dao



function getInnerText(handleObject)

{

    if(document.all)    // For IE

    {

        return handleObject.innerText;

    }else{// For Mozilla Family

        return handleObject.textContent;    

    }    

}



// Set innerText for object

// Writen by Thanh Dao

function setInnerText(handleObject,value)

{

    if(document.all)    // For IE

    {

        handleObject.innerText = value;

    }else{// For Mozilla Family

        handleObject.textContent = value;    

    }    

}



function clearBoldFormat(strHTML)

{

    return strHTML.replace(/<\/B>/gi,"").replace(/<B>/gi,"");    

}



// Chi duoc gan vao su kien onkeydown cua DIV

// Cac DIV duoc gan vao phai thoa dieu kien: 

//      contenteditable="true"

//      Co chay tren IE

function processEnterKeyForDIVOnIE()

{

    var key;

    

    if(window.event) //IE

    {

        key = window.event.keyCode; 

        if (key == 13)

        {

            var TempTR = window.document.selection.createRange();

            if(TempTR.pasteHTML)

            {

                TempTR.pasteHTML("<br><wbr>");

            }

            return false;                     

        }

    }

    return true;

}



function buildDocHTMLOnDialog(strEn,strVi)

{

    return "<div class=\"div-dialog_box_sub_content\"><span class=\"search-sentence\">" + encodeTagHTML(strEn)

                            + "</span><br><span class=\"search-sub_sentence\">" + encodeTagHTML(strVi) + "</span></div>";

}



function encodeTagHTML(str) {

    var div = document.createElement('div');

    var text = document.createTextNode(str);

    div.appendChild(text);

    

    return div.innerHTML;

}



// Check whether current window is popup window

function isPopUp()

{

    var strPage = window.location.href;



    if (strPage.indexOf(PN_POP_DOC_EDIT)!=-1 || strPage.indexOf(PN_POP_KEYWORD_EDIT)!=-1)

    {

        return true;

    }

    else

    {

        return false;

    }

}



// Focus any window

// Writen by Thanh Dao



function focusWindow(handleWindow)

{

    handleWindow.blur();

    handleWindow.focus();    

}



// Call strFunc function at paren window

function invokeFuncAtParentWindow(strFunc)

{

    eval("window.parent.opener." + strFunc + "");    

}



// Change to strURI page

function hrefWindow(strURI)

{

    window.location.href = strURI;

}



// Stop refresh page by keys

// Writen by Thanh Dao

function stopRefreshPage(e)

{

    if (!e)

    {

        var e = window.event;

    }



    var keycode = e.keyCode;

    if (e.which)

    {

        keycode = e.which;

    }   



    var isCtrl = false;

    if (e.ctrlKey)

    {

        isCtrl = true;        

    }



    if (keycode == 116 || (isCtrl && keycode == 82)) // 116 = F5, 82 = R

    {

        // Firefox and other non IE browsers

        if (e.preventDefault)

        {

            e.preventDefault();

            e.stopPropagation();

        }

        // Internet Explorer

        else if (e.keyCode)

        {

            e.keyCode = 0;

            e.returnValue = false;

            e.cancelBubble = true;

        }



        return false;

    }

}



function addEvent( obj, type, fn ) {

  if ( obj.attachEvent ) {

    obj['e'+type+fn] = fn;

    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}

    obj.attachEvent( 'on'+type, obj[type+fn] );

  } else
    obj.addEventListener( type, fn, false );
}



function removeEvent( obj, type, fn ) {

  if ( obj.detachEvent ) {

    obj.detachEvent( 'on'+type, obj[type+fn] );

    obj[type+fn] = null;

  } else

    obj.removeEventListener( type, fn, false );

}



// check if current window was open by parent window

// Writen by Thanh Dao

function checkParent() 

{

    if (opener != null){

        return true;

    }

    else {

        return false;

    }

}



// set focus to one control

// Writen by Thanh Dao

function focusControl(idControl)

{

    if (core.getObject(idControl))

    {

        core.getObject(idControl).focus();    

    }

}



// Disable/Enable one control

// Writen by Thanh Dao

function disableControl(idControl,isDisable)
{
    //@ThanhViet edited [20101223]
    if (core.getObject(idControl)){

        if (isDisable) {
            core.getObject(idControl)[0].style.cursor = "default";
            core.getObject(idControl)[0].disabled = isDisable;    
        }

        else
        {
            core.getObject(idControl)[0].style.cursor = "pointer";
            setTimeout(function() {
                core.getObject(idControl)[0].disabled = isDisable;
            }, 2000);
        }
        
    }
}
function disableLink(idControl, isDisable,strFunc) {
    //@ThanhViet edited [20101223]
    if (core.getObject(idControl)) {

        if (isDisable) {
            core.getObject(idControl)[0].style.cursor = "default";
           core.getObject(idControl).removeAttr("href");
        }
        else {
            core.getObject(idControl)[0].style.cursor = "pointer";
            setTimeout(function() {
                core.getObject(idControl).attr("href", strFunc);
            }, 2000);
        }
    }
}
// pad some character into string

// Writen by Thanh Dao

function str_pad(input, pad_length, pad_string, pad_type) {

    var half = '', pad_to_go;

 

    var str_pad_repeater = function (s, len) {

        var collect = '', i;

 

        while (collect.length < len) {collect += s;}

        collect = collect.substr(0,len);

 

        return collect;

    };

 

    input += '';

    pad_string = pad_string !== undefined ? pad_string : ' ';

    

    if (pad_type != 'STR_PAD_LEFT' && pad_type != 'STR_PAD_RIGHT' && pad_type != 'STR_PAD_BOTH') { pad_type = 'STR_PAD_RIGHT'; }

    if ((pad_to_go = pad_length - input.length) > 0) {

        if (pad_type == 'STR_PAD_LEFT') { input = str_pad_repeater(pad_string, pad_to_go) + input; }

        else if (pad_type == 'STR_PAD_RIGHT') { input = input + str_pad_repeater(pad_string, pad_to_go); }

        else if (pad_type == 'STR_PAD_BOTH') {

            half = str_pad_repeater(pad_string, Math.ceil(pad_to_go/2));

            input = half + input + half;

            input = input.substr(0, pad_length);

        }

    }

 

    return input;

}

// Check/uncheck All checkbox in table

// Writen by Thanh Dao

function checkedAllByTable(tableid,cellNumber,checkedStat)

{

    var table = core.getObject(tableid).children[2];

    if (table != undefined)

    { 

       var rowCount = table.rows.length;

       for (var i=0;i<rowCount;i++)

       {

            if(table.rows[i].cells[cellNumber])

            {

                table.rows[i].cells[cellNumber].children[0].checked = checkedStat;

            }

       }

    }

}

// Check first check box in the row when click onto the row

// Writen by Thanh Dao

function checkThisRow(e)

{       

	e["parentNode"]["children"][0].children[0].checked = !e["parentNode"]["children"][0].children[0].checked;

}



// Check/uncheck Top checkbox when All check box match check or some uncheck

// Writen by Thanh Dao

function checkAllStatus(tableid,checkboxid,cellNumber)

{

    if (!cellNumber)

    {

        cellNumber = 0;

    }

    var table = core.getObject(tableid).children[2];

    if (table != undefined)

    { 

       var rowCount = table.rows.length;

       var sum=0,realrow=0;;

       for (var i=0;i<rowCount;i++)

       {

          if (table.rows[i].cells[cellNumber])

          {

             realrow++;

             if (table.rows[i].cells[cellNumber].children[0].checked==true)

             {

                sum++;

             }

          }

       }

       core.getObject(checkboxid).checked = (sum==realrow);

    }

}

// TODO: TINH

function checkRegexp(strvalue,regexp) {



	return regexp.test( strvalue );

}

function checkEmail(email)

{

    return checkRegexp(email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);

}

function getTextOfSelect(idofobj, sval)

{

    var listOptions = core.getObject(idofobj).options;

    var n = listOptions.length;

    var val;

    for(var i = 0 ; i < n ; i++){

        val = listOptions[i].value;

        if(val == sval)

            return listOptions[i].text;

    }

}



function implode (glue, pieces) 

{

    var i = '', retVal='', tGlue='';

    if (arguments.length === 1) 

    {        

        pieces = glue;

        glue = '';

    }

    if (typeof(pieces) === 'object') 

    {

        if (pieces instanceof Array) 

        {            

            return pieces.join(glue);

        }

        else 

        {

            for (i in pieces) 

            {

                retVal += tGlue + pieces[i];                

                tGlue = glue;

            }

            return retVal;

        }

    }    

    else 

    {

        return pieces;

    }

}



/**

 * gan mot ham cho su kien nhan phim nao đo cua mot doi tuong

 *

 * @param event e event onkeypress of object

 * @param int keyCode code of key press

 * @param string exe function name 

 * @return no value

 * @author TinhDoan added [20100503]

 */

function executeFuncDependKeycode(e,keyCode,exe)

{

    var curKey;

    if(window.event)

    {

        curKey = window.event.keyCode;

    }

    else

    {

        curKey = e.which;

    }

    if (curKey==keyCode)

    {

        eval(exe);

    }

}

/**

* Increase pageview for HelloChao.com

* @param int itype: 1->call from search.php  

* @author DoNguyen added [20100506]

*

*/

function increasePageView(iType)

{

    // Store links to array

    var arrLinks = new Array(8);

    // Assign links for array

    arrLinks[0] = "keyword.php";

    arrLinks[1] = "forum.php";

    arrLinks[2] = "help.php?txtTut=1";

    arrLinks[3] = "help.php?txtTut=2";

    arrLinks[4] = "help.php?txtTut=3";

    arrLinks[5] = "help.php?txtTut=4";

    arrLinks[6] = "user.php";

    arrLinks[7] = "user.php?d=30";

    

    var iStart = 500;

    if (iType == 1) // From search.php page

    {

        iStart = 4000;        

    }    

    // Call 4 request in 2 seconds

    setTimeout("increasePageView_request('" + arrLinks[randomInteger(0,1)] + "')", iStart);   

    setTimeout("increasePageView_request('" + arrLinks[randomInteger(2,3)] + "')", iStart + 500);   

    setTimeout("increasePageView_request('" + arrLinks[randomInteger(4,5)] + "')", iStart + 1000);   

    setTimeout("increasePageView_request('" + arrLinks[randomInteger(6,7)] + "')", iStart + 1500);   

}

function increasePageView_request(strURL)

{

    var ajax = new Ajax("GET");	

	ajax.SendRequestToServerWithCustomMsg(strURL, null , null, true, null,null,true); 

}



/**

* Get an integer random between iFrom & iTo

* @author DoNguyen added [20100506]

*

*/

function randomInteger(iFrom, iTo)

{

    // Get duration

    var iDuration = iTo - iFrom;

    

    // Get random from 0 -> iDuration

    var iReturn = Math.floor(Math.random()*(iDuration + 1));

    

    // Return value between iFrom & iTo

    return (iReturn + iFrom);

}

/**

* chuyen gia tri text-xml tra ve thanh mot mang gia tri

*

* param string text la mot chuoi

* paser text nhan tu server tra ve thanh mot mang gia tri

* @author TinhDoan added [20100522]

*

*/

function parserXML(text)

{

//alert(text);

//    text = " <?xml version=\"1.0\"?><r><h><h1>0</h1><h2>0</h2><h3>0</h3></h><c><rs>1</rs><inf><![CDATA[<div class=\"frame_fb_comment\"><div class=\"frame_title_fb_comment\" onmouseover=\"showObject('linkcfc81e128d9d4c21631~020f89cc1421MO');\" onmouseout=\"hideObject('linkcfc81e128d9d4c21631~020f89cc1421MO');\">"+

//		"<div class=\"divinline username_fb_comment\">"+

//		"   <b><a class=\"m_link\" href=\"javascript:viewProfile_login('c4ca1238a0b92382tdcc~09a6f7584Ms');\">test</a></b>"+

//		"	<span class=\"time-ago\"> - 1 phút</span>"+

//		"</div>"+

//		"<div id=\"linkcfa87f1679a2f3e11d1~81067b754241MO\" class=\"menu_fb_comment\">"+

//		"<div class='divinline'>&nbsp;<input  title='Bạn đã like nội dung này.' width='19px' height='17px'  class='noneClick middleTitle' id='btnLikec81e128d9d4c21631~020f89cc1421MO' name='btnLikec81e128d9d4c21631~020f89cc1421MO'  type='image' src='images/like2.png'  \><span class='like_amount'><label class='noneClick' title='Xem danh sách người like'  id='likeAmountc81e128d9d4c21631~020f89cc1421MO' >&nbsp;0&nbsp;&nbsp;</label></span>&nbsp;&nbsp;</div>"+

//		"<a href=\"forum.php?cofuserid=c4ca1238a0b92382tdcc~09a6f7584Ms\"><img class='img_fb_comment_relative' src=\"images/user-comment.png\" title=\"Xem những comment liên quan tới test\" /></a>"+

//		"</div>"+

//		"<div class=\"clearfix\"></div>"+

//	"</div>"+

//	"<div class=\"content_fb_comment\"><p>aaaaaaaaaaaaaaa</p></div>"+

//	"</div><div class=\"clearfix hgt5\"></div>]]></inf><cui>0</cui></c></r>";

    var xmlDoc;

    //debugger;

    if (window.DOMParser)

    {

        parser=new DOMParser();

        // TODO: TinhDoan edited [20100522] - can phai xem lai cho nay

        // DoNguyen editted [20100522] - Anh trim() no truoc khi dung cho chac an (vi khong biet co phai luon luon du 2 ky tu khong)

        // Anh cung chua biet nguyen nhan vi sao du 2 ky tu nay, anh nghi la do header, nhung anh doi roi van khong an thua gi

        var text_temp = core.trim(text);//.substr(2);

        xmlDoc=parser.parseFromString(text_temp,"text/xml");

    }

    else // Internet Explorer

    {

        //var text_temp = core.trim(text);//.substr(2);

        xmlDoc=new ActiveXObject("Microsoft.XMLDOM");

        xmlDoc.async="false";

        xmlDoc.loadXML(text); 

    }

    var root = xmlDoc.getElementsByTagName("r")[0];

    var intArray = root.childNodes.length;

    var arrResult = new Array(intArray);

    var i, j;

    var node, intNode, nodeValue;

    // TODO: DoNguyen reviewed - O day co mot vai diem khong hop ly lam

    // 1. O server truyen vao la KEY-VALUE, nhung o client lai parse ra la INDEX-VALUE, anh muon van la KEY-VALUE

    //    (tuc la se khong dung "arrValue.push" ma se la arrValue[ten cua node]=...)

    //    de coder luc su dung lay gia tri cho de.

    // 2. Khong nen dung "arrResult.push" ma hay kiem tra neu la con cua node "h" thi gan vao arrResult[0],

    //    neu la con cua node "c" thi gan vao arrResult[1].

    //    Nhu vay minh chac chan chay dung, minh push kieu nay anh so no khong giong nhau giua cac browser.

    // => Khi su dung ket qua function nay, chung ta se goi nhu sau: 

    //    - Doi voi Header: arrResult[0]["h1"], arrResult[0]["h2"], arrResult[0]["h3"]

    //    - Doi voi noi dung: arrResult[1]["rs"], arrResult[1]["inf"],...

    for (i=0; i<intArray; i++)

    {

	    node = root.childNodes[i];

	    intNode = node.childNodes.length;

	    var arrValue = new Array(intNode);

	    for (j=0; j<intNode; j++)

	    {

		    nodeValue = node.childNodes[j];

		    arrValue[nodeValue.nodeName] = nodeValue.childNodes[0]==null?"":nodeValue.childNodes[0].nodeValue;

	    }

	    switch(node.nodeName)

	    {

	        case "h":

	            arrResult[0] = arrValue;

	            break;

	        case "c":

	            arrResult[1] = arrValue;

	            break;

	        default:

	            break;

	    }

    }

    

    return arrResult;

}



function adjustToCenterScreen(objDiv,width,height)

{

    var iWidthScreen, iHeightScreen, iWidthDiv, iHeightDiv, posX, posY;

    

    // Lay width, height man hinh

    iWidthScreen = core.getInsideWindowWidth();

    iHeightScreen = core.getInsideWindowHeight();    



    // Lay width, height cua div    

    iWidthDiv = (existVariable(width) && width!=null) ? width : core.getObjectWidth(objDiv);

    iHeightDiv = (existVariable(height) && height!=null) ? height : core.getObjectHeight(objDiv);



    // Tinh toan toa do X,Y

    posX = Math.floor((iWidthScreen - iWidthDiv) / 2);

    posY = Math.floor((iHeightScreen - iHeightDiv) / 2);



    posX = posX <=0 ? 0 : posX;

    posY = posY <=0 ? 0 : posY;



    // Adjust to center

    core.moveTo(objDiv, posX, posY);

}

function adjustToTopCenterScreen(objDiv,width,height)

{

    var iWidthScreen, iHeightScreen, iWidthDiv, iHeightDiv, posX, posY;

    

    // Lay width, height man hinh

    iWidthScreen = core.getInsideWindowWidth();

    iHeightScreen = core.getInsideWindowHeight();    



    // Lay width, height cua div    

    iWidthDiv = (existVariable(width) && width!=null) ? width : core.getObjectWidth(objDiv);

    iHeightDiv = (existVariable(height) && height!=null) ? height : core.getObjectHeight(objDiv);



    // Tinh toan toa do X,Y

    posX = Math.floor((iWidthScreen - iWidthDiv) / 2);

    posY = Math.floor((iHeightScreen - iHeightDiv)* 1/ 5);



    posX = posX <=0 ? 0 : posX;

    posY = posY <=0 ? 0 : posY;



    // Adjust to center

    core.moveTo(objDiv, posX, posY);

}

/**

* Kiem tra xem bien variable co ton tai hay khong?

* variable co the la: thuoc tinh, doi tuong, bien, tham so trong ham,...

*

* variable bien can kiem tra

* return true: neu bien nay ton tai HOAC variable==null, false: khong ton tai

* @author DoNguyen added [20100606]

*

*/

function existVariable(variable)

{

    if(typeof(variable)!='undefined'){

        return true;

    }else{

        return false;

    }    

}

/**

* Khong thuc hien mot su kien nao do

*

* param event event la mot su kien nao do

* @author TinhDoan added [20100607]

*

*/

function dontEvent(event)

{

    if (event.preventDefault){

        event.preventDefault();  // stop the event bubble

        event.stopPropagation();

    } else {

        window.event.keyCode=8;

        window.event.returnValue=false;

    }

    return false;

}



// Decrease or Increase value in "number of messages", "number of sub messages" or "number of docs"

// typeInfo: 1->Message, 2->Sub message, 3->Doc

function changeAmount(spanID, typeInfo, amountOfDecrease)

{

    var objSpan = core.getObject(spanID);

    if (!objSpan)

    {

        return;

    }

    

    var intValue = 0;

    var textValue = "";   

    

    // Get innerText     

    textValue = getInnerText(objSpan);

    

    if (!textValue)

    {

        textValue = "0";

    }

    

    // Delete ( and )

    textValue = textValue.replace("(","").replace(")","");

    intValue = parseInt(textValue) + amountOfDecrease;



    if (typeInfo == 1) // Message

    {

        if (intValue > 0)

        {

            textValue == 1 ? 2 : textValue; 

            objSpan.innerHTML = "<b>(" + intValue + ")</b>";                        

        }else{

            objSpan.innerHTML = "";                                

        }        

    }else if(typeInfo == 2){

        if (intValue > 0)

        {

            intValue = (intValue==1) ? 2:intValue;

            objSpan.innerHTML = "&nbsp;(" + intValue + ")";                        

        }    

    }else if(typeInfo == 3) // Doc

    {

        if (intValue >= 0)

        {

            objSpan.innerHTML = "<b>" + intValue + "</b>";                        

        }            

    }

}



// không cho phép user ấn phím enter

function noEnter(e){

  var e  = (e) ? e : ((event) ? event : null);

  var node = (e.target) ? e.target : ((e.srcElement) ? e.srcElement : null);

  if ((e.keyCode == 13)) {return false;}

}



var ID_DIV_TMP_AUTO_RESIZE = "_idDivTmpAutoResizeTextarea_"; 

function autoResizeTextarea(objControl)

{

    var objTmp = core.getObject(ID_DIV_TMP_AUTO_RESIZE);

    // Dung parseInt(...) de loai bo chu "px" o cuoi trong gia tri cua width

    var widthTmp = objTmp.style.width ? parseInt(objTmp.style.width) : core.getObjectWidth(ID_DIV_TMP_AUTO_RESIZE);

    var widthControl = objControl.style.width ? objControl.style.width : core.getObjectWidth(core.getObjectID(objControl));

    

    if(widthTmp != widthControl)

    {

        objTmp.className = objControl.className;    

        core.setObjectWidth(ID_DIV_TMP_AUTO_RESIZE,widthControl);  

    }

    

    objTmp.innerHTML = objControl.value.replace(/\r/g,'').replace(/\n/g,"<br>");

    core.setObjectHeight(core.getObjectID(objControl),core.getObjectScrollHieght(ID_DIV_TMP_AUTO_RESIZE)); 

}

function showObject(obj) {

    var elem = (typeof obj == 'string') ? core.getObject(obj) : obj;

    if (elem)

        elem.style.display = "block";

}

function hideObject(obj) {

    var elem = (typeof obj == 'string') ? core.getObject(obj) : obj;

    if (elem)

        elem.style.display = "none";

}

/**

 * kiểm tra một node có phải la con của nó không

 *

 * @param string/object parent có thể là id của node hoặc object node cha

 * @param string/object child có thể là id của node hoặc object node con

 * @return false không phải là con, ngược lại đúng.

 * @author TinhDoan added [20101214]

 *

 */	

function isChildNode(parent, child)

{

    if(typeof parent == 'string') parent=core.getObject(parent);

    if(typeof child == 'string') child=core.getObject(child);

    while(!child.nodeName.match(/^(HTML|BODY)/)){

        if(child==parent) return true;

        child=child.parentNode;

    }

    return false;    

}

function splitDate(strDate) {

    arrDate= strDate.split("-");

    return {d: arrDate[0],m:  arrDate[1],y:  arrDate[2]};

}

/*Loại bỏ các thẻ tag*/
function stripHTML(oldString) {

    var newString = "";
    var inTag = false;
    for (var i = 0; i < oldString.length; i++) {

        if (oldString.charAt(i) == '<') inTag = true;
        if (oldString.charAt(i) == '>') {
            if (oldString.charAt(i + 1) == "<") {
                //dont do anything
            }
            else {
                inTag = false;
                i++;
            }
        }

        if (!inTag) newString += oldString.charAt(i);

    }

    return newString;
}